package com.cgame.game;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

import org.hibernate.sql.Delete;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;

public class GameFactory {
	static Map<String, Game> gamelist=new HashMap<String, Game>();
	static{
		JsonObject param=new JsonObject();
		param.addProperty("wolfnumber", 1);
		param.addProperty("citizennumber", 1);
		param.addProperty("forsee", true);
		param.addProperty("witch", true);
		
		Game game=new Game();
		game.creategame(param);
		addGame(game);
	}
	public static Game getGame(String id){
		return gamelist.get(id);
	}
	public static Map<String, Game> listGame(){
		return gamelist;
	}
	public static void addGame(Game game){
		gamelist.put(game.gamename,game);
	}
	public static JsonArray getGameList() {
		JsonArray result=new JsonArray();
		JsonObject temp;
		for (Entry<String, Game> entry:gamelist.entrySet()){
			temp=new JsonObject();
			temp.addProperty("name", entry.getKey());
			result.add(temp);
		}
		return result;
	}
	public static synchronized void delete(String gameId){
		gamelist.remove(gameId);
	}
}
